package cn.com.miao.lynx.plugin.sms.model;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.HashMap;

/**
 * SmsRequestParam
 *
 * @title: SmsRequestParam
 * @description:
 * @author: dengmiao
 * @create: 2020-01-10 11:10
 **/
public class SmsRequestParam {

    private static final ObjectMapper objectMapper = new ObjectMapper();

    /**
     * 参数集合
     */
    private static HashMap<String, Object> params = new HashMap<>();

    /**
     * 写入参数到集合
     * @param name  参数名
     * @param value 参数值
     * @return 本类实例
     */
    public SmsRequestParam put(String name, Object value) {
        params.put(name, value);
        return this;
    }

    /**
     * 参数转换为json字符串
     *
     * @return json
     */
    public String getParamJson() {
        try {
            return objectMapper.writeValueAsString(params);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return StrUtil.EMPTY_JSON;
    }
}
